package com.qunar.flight.myserver;

import java.nio.channels.SelectionKey;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;

public class Acceptor implements Runnable {
	ServerSocketChannel ssc;
	Dispatcher d;

	Acceptor(ServerSocketChannel ssc, Dispatcher d) {
		this.ssc = ssc;
		this.d = d;
	}

	public void run() {
		for (;;) {
			try {
				System.out.println(getClass());
				SocketChannel sc = ssc.accept();
				System.out.println("��⵽�����½�sc:"+sc);
				sc.configureBlocking(false);
				RequestHandler rh = new RequestHandler(sc);
				d.register(sc, SelectionKey.OP_READ, rh);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}